let fs = require("fs");
let user = { username: "admin1", password: "12345" };
let fd = fs.readFileSync(__dirname + "/persons.json", "utf8");
let arr = JSON.parse(fd.toString());



let reg = arr.findIndex((item) => {
    return item.username == user.username && item.password == user.password
})

if (reg == -1) {
    arr.push(user);
    console.log("注册成功");
    fs.writeFileSync(__dirname + "/persons.json",JSON.stringify(arr));
} else {
    console.log("该用户已被注册")
}